package com.jspgou.cms.action.front;

import static com.jspgou.cms.Constants.MEMBER_SYS;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.jspgou.cms.entity.ShopMember;
import com.jspgou.cms.web.CmsUtils;
import com.jspgou.cms.web.ShopFrontHelper;
import com.jspgou.cms.web.SiteUtils;
import com.jspgou.common.web.springmvc.MessageResolver;
import com.jspgou.core.entity.Website;

@Controller
public class ShopScoreAct {
	private static final Logger log = LoggerFactory.getLogger(ShopScoreAct.class);
	
	/**
	 * 会员积分页
	 */
	public static final String MEMBER_SCORE = "tpl.myscore";
	
	@RequestMapping(value = "/shopScore/myscore*.jspx")
	public String getMyScore(String cl,Integer status,Integer useStatus,String startTime,
			String endTime,HttpServletRequest request, ModelMap model) {
		Website web = SiteUtils.getWeb(request);
		ShopMember member=CmsUtils.getMember(request);
		//用户没有登录，跳转到登录页
		if(member == null){
			return "redirect:../login.jspx";
		}
		model.addAttribute("cl", cl);
		model.addAttribute("status", status);
		model.addAttribute("useStatus", useStatus);
		model.addAttribute("startTime", startTime);
		model.addAttribute("endTime", endTime);
		model.addAttribute("historyProductIds", "");
		Cookie[] cookie = request.getCookies();
		for(int i=0;i<cookie.length;i++){
			if(cookie[i].getName().equals("shop_record")){
				String str = cookie[i].getValue();
				model.addAttribute("historyProductIds", str);
				break;
			}
		}
		ShopFrontHelper.setCommonData(request, model, web);
		ShopFrontHelper.frontPageData(request, model);
		return web.getTplSys(MEMBER_SYS, MessageResolver.getMessage(request,
				MEMBER_SCORE), request);
	}

}
